vtgate: add viper config to ignore specified query shapes from query log#20174
vtgate: add viper config to ignore specified query shapes from query log#20174ChaitanyaD48 wants to merge 4 commits into
Conversation
Signed-off-by: ChaitanyaD48 <chaitanya.d48@gmail.com>
Signed-off-by: ChaitanyaD48 <chaitanya.d48@gmail.com>
Signed-off-by: ChaitanyaD48 <chaitanya.d48@gmail.com>
Signed-off-by: ChaitanyaD48 <chaitanya.d48@gmail.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in vtgate query-log ignore mechanism so operators can suppress configured SQL query shapes from /debug/querylog output. It introduces a dynamically reloadable Viper flag, query-shape normalization logic, executor integration, and tests/help-output updates.
Changes:
- Added
querylogignorepackage for parsing inline/file-backed ignore patterns and matching normalized query shapes. - Routed vtgate executor query-log emission through a new
sendQueryLoghelper. - Added unit/integration coverage and updated vtgate/vtcombo flag help snapshots.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
go/vt/vtgate/querylogignore/querylogignore.go |
Adds flag registration, pattern loading, canonicalization, and ignore matching. |
go/vt/vtgate/querylogignore/querylogignore_test.go |
Covers ignore-set parsing, normalized matching, raw fallback, file loading, and empty fast path. |
go/vt/vtgate/executor.go |
Applies ignore matching before sending vtgate query-log entries. |
go/vt/vtgate/executor_querylog_ignore_test.go |
Verifies executor-level suppression and non-matching query logging. |
go/flags/endtoend/vtgate.txt |
Updates vtgate help output for the new flag. |
go/flags/endtoend/vtcombo.txt |
Updates vtcombo help output for the new flag. |
| GetFunc: func(v *viper.Viper) func(key string) *IgnoreSet { | ||
| return func(key string) *IgnoreSet { | ||
| newVal := v.GetString(key) | ||
| if cur, ok := v.Get(key).(*IgnoreSet); ok && cur.source == newVal { |
|
Promptless prepared a documentation update related to this change. Triggered by PR #20174 Added documentation for the new Review: vtgate: add viper config to ignore specified query shapes from query log |
Description
Operators can now suppress specific SQL query shapes from the vtgate query log via a new opt-in
--query-log-ignore-patternsflag. Empty by default.How it works
go/vt/vtgate/querylogignoreholds the flag (Viper-managed, dynamically reloadable), the parsedIgnoreSet, and theShouldIgnorelookup.sqlparser.RedactSQLQuery, then type annotations (/* INT64 */) and bind-variable names (:vtg1,:redacted1,:x) are stripped so equivalent shapes compare equal regardless of literal values. Patterns that fail to parse fall back to a case-insensitive, trimmed raw-string match.sendQueryLoghelper, called from the threequeryLogger.Sendsites inExecute,StreamExecute, andPrepare).Usage
--query-log-ignore-patterns='select 1 from dual,select $$,PING'@prefix; one pattern per line;#comments and blank lines are skipped):--query-log-ignore-patterns='@/etc/vt/ignored-queries.txt'Test plan
Automated tests
go/vt/vtgate/querylogignore/querylogignore_test.go.go/vt/vtgate/executor_querylog_ignore_test.go.TestHelpOutput/vtgate,TestHelpOutput/vtcombo, andTestHelpOutput/vtgateclienttestall pass with the new flag added togo/flags/endtoend/vtgate.txtandgo/flags/endtoend/vtcombo.txt.Manual testing via
examples/localBrought up a local cluster (
./101_initial_cluster.sh) with vtgate configured in following ways:a) CLI flag, inline list
--query-log-ignore-patterns='select 1 from dual,PING'b) CLI flag, file form
--query-log-ignore-patterns='@/tmp/ignored.txt'where/tmp/ignored.txtcontained patterns one per line, plus blank lines and#-prefixed comments to confirm they're skipped.c) Viper config file (for dynamic-reload verification)
--config-file=/tmp/vtgate.yaml--config-file-not-found-handling=errorwith/tmp/vtgate.yamlcontainingquery_log_ignore_patterns: "@/tmp/ignored.txt".For each setup, in two terminals:
curl -sN http://localhost:15001/debug/querylogto stream the log.mysql -h 127.0.0.1 -P 15306 -e '<query>'to send traffic.Verified:
select 9999 from dualis suppressed whenselect 1 from dualis configured (different literal, same canonical shape).PINGis suppressed via raw-string fallback.select $$is suppressed (parses successfully in current sqlparser; both pattern and query land in the same canonicalselect $$ from dualbucket).select * from customer) still appears in the log stream./tmp/vtgate.yamland saving, the new patterns take effect on the next query without restarting vtgate (Viper dynamic reload via fsnotify).Related Issue(s)
Fixes #20173
Checklist